<?php

 
 class PageUtility
 {
	public function pagination($array,$rows,$currentPage) {
		
		$totalRows = count($array);
		$data = array();
		$rowcnt = 0;
		$rowctr = 0;
		if($currentPage == 1 || $currentPage == 0) 
			$page = $currentPage;
		else 
			$page = ($currentPage * $rows) - $rows;
			
			
		
		foreach($array as $key => $value){
			if($rowctr != $rows) {
				if($rowcnt >= $page) {
					$data[$key] = $value;
					$rowctr = $rowctr + 1;
					
				}
				$rowcnt = $rowcnt + 1;
				
			} else {
				break;
			}
		}
		//echo $totalRows;
		//ECHO "<pre>";print_r($data);echo "</pre>";
		return $data;
		
	}
	
	public function pagelength($rows,$pagelength) {
		
		$page = ($pagelength/$rows);
		$data = array();
		$cnt = 1;
		for($x = 0; $x < $page;$x++) {
			for($y = 0;$y < $rows;$y++) {
				if($cnt <= $pagelength) 
					$data[$x][] = $cnt;
				$cnt = $cnt + 1;
			}
			
		}
		
		return $data;
		
	}
 }
 
 ?>